#include "gamemanager.h"
#include "baseapplication.h"

using std::list;
using namespace EPOC;

GameManager::GameManager(BaseApplication *pApplication)
{
	m_pApplication = pApplication;
	SetClassID(kCLASSID_CONTENTMANAGER);
}

GameManager::~GameManager()
{
	GameManager::Cleanup();
}

void GameManager::Cleanup()
{
	for(list<BaseObject*>::iterator it = m_rUpdateContainer.begin(); it != m_rUpdateContainer.end(); it++)
	{
		delete (*it);
	}
	m_rUpdateContainer.clear();
}

bool GameManager::Initialize()
{
	
	return true;
}

 
bool GameManager::Update( float fTimeDelta)
{
	for(list<BaseObject*>::iterator it = m_rUpdateContainer.begin(); it != m_rUpdateContainer.end();)
	{
		if((*it)->Update(fTimeDelta) == false)
			it = m_rUpdateContainer.erase(it);
		else
			it++;
	}

	return true;
}

void GameManager::AddUpdateObject(BaseObject* pObject)
{
	if(pObject)
		m_rUpdateContainer.push_back(pObject);
}

void GameManager::RemoveUpdateObject(BaseObject *pObject)
{
	if(!m_rUpdateContainer.empty())
		m_rUpdateContainer.remove(pObject);
}